package com.data.service;

import com.data.mapper.DataMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class DataService {
    @Autowired
    private DataMapper dataMapper;

    public List<Map> listTables(String schema){
        return dataMapper.listTables(schema);
    }

    public List<Map> listSchemas(){
        return dataMapper.listSchemas();
    }

    public List<String> listTableColumn(String schema, String table){
        return dataMapper.listTableColumn(schema, table);
    }

    public PageInfo<Map> listTableData(
            String schema,
            String table,
            int pageNum,
            int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<Map> list = dataMapper.listTableData(schema+"."+table);
        PageInfo<Map> pageInfo = new PageInfo<Map>(list);
        return pageInfo;
    }

    public int getAllCount(String schema,
                           String table){
        int count = dataMapper.getAllCount(schema+"."+table);
        return count;
    }

    public Object createSchema(String schema){
        return dataMapper.createSchema(schema);
    }

    public Object createTable(String createTable){
        return dataMapper.createTable(createTable);
    }
}
